package com.atsmart.app.exception;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;

public class GlobalExceptionHandler {
    public static String TAG = "com.newegg.app.trace.GlobalExceptionHandler";
    private static HandlerThread localHandlerThread;
    @SuppressWarnings("unused")
    private static Handler handler;

    public static void register(Context paramContext, String activityName) {
        PackageManager localPackageManager = paramContext.getPackageManager();
        GlobalExceptionInfo info = new GlobalExceptionInfo();
        try {
            PackageInfo localPackageInfo = localPackageManager.getPackageInfo(
                    paramContext.getPackageName(), 0);

            info.AppVersion = localPackageInfo.versionName;
            info.AppPacekage = localPackageInfo.packageName;
            info.FilesPath = paramContext.getFilesDir().getAbsolutePath();
            info.PhoneModel = Build.MODEL;
            info.AndroidVersion = Build.VERSION.RELEASE;
            info.ActivityName = activityName;// paramContext.getClass().getName();
        } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
            localNameNotFoundException.printStackTrace();
        }
        final GlobalExceptionInfo info2 = info;
        localHandlerThread = new HandlerThread(info.ActivityName);
        localHandlerThread.start();
        handler = new Handler(localHandlerThread.getLooper());
        Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler(
                info2,paramContext));
    }

    public static void register(Context paramContext) {
        register(paramContext, paramContext.getClass().getName());
    }
}
